package com.xnyzc.lhy.didi.controller.synchronization;

import com.alibaba.fastjson.JSON;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.penum.order.EOrderChannelType;
import com.xnyzc.lhy.didi.entity.param.synchronization.StatusCallbackParam;
import com.xnyzc.lhy.didi.service.tongcheng.TcOrderStatusSyncService;
import com.xnyzc.lhy.didi.service.xiecheng.XcOrderStatusSyncService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单状态同步
 * </p>
 *
 * @author rhr
 * @since 2020-08-17
 */
@Slf4j
@RestController
@RequestMapping("oa/order/status")
public class OrderStatusSyncController {

    @Autowired
    private XcOrderStatusSyncService xcOrderStatusSyncService;

    @Autowired
    private TcOrderStatusSyncService tcOrderStatusSyncService;

    /**
     * 订单状态同步
     *
     * @param statusCallbackParam
     * @return
     */
    @ApiOperation(value = "订单状态同步", notes = "订单状态同步")
    @PostMapping(value = "/statusSync")
    public Rv statusSync(@ApiParam(name =
            "locationSyncParam", value = "订单状态同步") @RequestBody StatusCallbackParam statusCallbackParam) {
        log.info("StatusSync-" + JSON.toJSONString(statusCallbackParam));
        EOrderChannelType channelType = EOrderChannelType.findById(statusCallbackParam.getChannel());
        switch (channelType) {
            case tongcheng: {
                return tcOrderStatusSyncService.handle(statusCallbackParam);
            }
            case xiecheng: {
                return xcOrderStatusSyncService.handle(statusCallbackParam);
            }
            case ordinary: {
                return Rv.wrap();
            }
            default: {
                return Rv.error(EErrorCode.noData);
            }
        }
    }
}
